#include <stdio.h>
#include <stdlib.h>
#define LENGTH 2000
void selectSort(int a[], int length)
{
	length	=	LENGTH;
	for (int i = 0; i <= length - 1; i++)
	{
		int min = a[i];
		int minIndex = i;
		for (int j = i + 1; j <= length - 1; j++)
		{
			if (a[j] < min )
			{
				min = a[j];
				minIndex = j;
			}
		}
		//交换
		int tmp = a[i];
		a[i] = a[minIndex];
		a[minIndex] = tmp;
	}
}
void printArray(int a[], int length)
{
	length	=	LENGTH;
	for (int i = 0; i <= length - 1; i++)
		printf("%d ", a[i]);

	printf("\n");
}
int main()
{
	int length	=	LENGTH;
	int a[length];
	for (int i = 0; i < length; i++)
	{
		a[i] = rand() % 1000;
	}
	printArray(a, length);
	selectSort(a, length);
	printArray(a, length);
}
